package test.exigen.einheritance;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: senior
 * Date: 12.09.12
 * Time: 14:06
 * To change this template use File | Settings | File Templates.
 */
public class TimeAddToList {
    public static final int SIZE = 10000000;
    public static void main(String[] args) throws InterruptedException {
        List arrayList = new ArrayList();
        LinkedList linkedList = new LinkedList();
        Thread.sleep(10000);
        for(int i = 0; i < 10; i++){
            test(arrayList, linkedList);
        }

   }

    private static void test(List arrayList, LinkedList linkedList) {
        System.out.println("array list add time = " + addTest(arrayList) + "ms ");
        arrayList.clear();
        System.out.println("linked list add time = " + addTest(linkedList)+ "ms ");
        linkedList.clear();
    }

    private static long addTest(List list) {
        long start = System.currentTimeMillis();
        for(int i = 0; i < SIZE ; i++) {
            list.add(new MyObject(i));
        }
        long end = System.currentTimeMillis();
       return end - start;
    }
    static class MyObject{
        private int i;
        private Integer s ;

        public MyObject(int i) {
            this.i = i;
            s = i + i;
        }
    }
}

